package com.example.design.ticket.proxy;

import ch.qos.logback.classic.turbo.TurboFilter;
import com.example.design.ticket.director.AbstractDirector;
import com.example.design.ticket.director.Director;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class DirectorProxy extends AbstractDirector {

    //关联被代理角色
    @Resource
    private Director director;

    @Override
    public Object buildTicket(String type, String productId, String content, String title, String bankInfo, String taxId) {
        //前置处理，通过产品id获取产品信息
        String product = getProduct(productId);
        //前置处理，校验银行卡信息
        if (bankInfo != null && !validate(bankInfo)){
            return null;
        }
        //代理 direct 类的buildTicket方法
        return director.buildTicket(type, product, content, title, bankInfo, taxId);
    }

    //前置处理，通过产品id获取产品信息
    private String getProduct(String productId){
        return "通过产品id获取产品信息";
    }

    //前置处理，校验银行卡信息
    private boolean validate(String bankInfo){
        System.out.println("校验银行卡信息");
        return true;
    }
}
